
local coroutine = coroutine

function status()
    print("co1's status :"..coroutine.status(co1).." ,co2's status: "..coroutine.status(co2))
end
co1 = coroutine.create(function ( a )
    print("arg1 is :"..a)
    status()
    local stat,rere = coroutine.resume(co2, "2")
    print("1 resume's return is "..rere)
    status()
    local stat2,rere2 = coroutine.resume(co2, "4")
    print("2 resume's return is "..rere2)
    local arg = coroutine.yield("6")
end)
co2 = coroutine.create(function ( a )
    print("arg2 is :"..a)
    status()
    local rey = coroutine.yield("3")
    print("yeild's return is " .. rey)
    status()
    coroutine.yield("5")
end)

--主线程执行co1,传入字符串“main thread arg”
stat,mainre = coroutine.resume(co1,"1")
status()
print("last return is "..mainre)

--[[
    arg1 is :1
    co1's status :running ,co2's status: suspended
    arg2 is :2
    co1's status :normal ,co2's status: running
    1 resume's return is 3
    co1's status :running ,co2's status: suspended
    yeild's return is 4
    co1's status :normal ,co2's status: running
    2 resume's return is 5
    co1's status :suspended ,co2's status: suspended
    last return is 6
]]